package com.example.websocketdemo.service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.example.websocketdemo.config.WebSocketTest;

import java.io.IOException;

public class ProductionDataService {


    public void t(String bitNumber, Double AV) throws IOException {
        JSONObject jsonObject = new JSONObject();
        JSONObject xinxi = new JSONObject();
        JSONObject xinxi1 = new JSONObject();
        JSONObject xinxi2 = new JSONObject();
        JSONObject xinxi3 = new JSONObject();

        JSONArray Array = new JSONArray();
        jsonObject.put("instruction", "shengchanshuju");

        if (bitNumber.equals("SCADA_DO_HV2611")) {
            xinxi1.put("id", "SCADA_DO_HV2611");
            xinxi.put("所属区域名称", "车辆装车站");
            xinxi.put("设备名称", "HV-2611紧急切断阀");
            xinxi.put("指标名称", "HV2611紧急切断阀控制");
            xinxi.put("实时●数值", String.format("%.2f", AV) + " MPa");
            xinxi.put("单位", "");
            xinxi.put("低低报", "-");
            xinxi.put("低报", "-");
            xinxi.put("高报", "-");
            xinxi.put("高高报", "-");
            xinxi.put("量程下限", "-");
            xinxi.put("量程上限", "-");
            xinxi.put("位号", "SCADA_DO_HV2611");
            xinxi.put("重点监管工艺细类", "Z1");
            xinxi.put("安全仪表连锁回路总数", "-");
            xinxi.put("安全仪表系统投用状态的指标编码", "-");
            xinxi.put("安全仪表连锁回路旁路数的指标编码", "-");
            xinxi.put("issue", "true");
            Array.add(xinxi);
        } else if (bitNumber.equals("SCADA_DI_HV2611")) {
            xinxi1.put("id", "SCADA_DI_HV2611");
            xinxi1.put("所属区域名称", "车辆装车站");
            xinxi1.put("设备名称", "HV-2611紧急切断阀");
            xinxi1.put("指标名称", "HV2611紧急切断阀控制");
            xinxi1.put("实时●数值", String.format("%.2f", AV) + " MPa");
            xinxi1.put("单位", "");
            xinxi1.put("低低报", "-");
            xinxi1.put("低报", "-");
            xinxi1.put("高报", "-");
            xinxi1.put("高高报", "-");
            xinxi1.put("量程下限", "-");
            xinxi1.put("量程上限", "-");
            xinxi1.put("位号", "SCADA_DI_HV2611");
            xinxi1.put("重点监管工艺细类", "Z1");
            xinxi1.put("安全仪表连锁回路总数", "-");
            xinxi1.put("安全仪表系统投用状态的指标编码", "-");
            xinxi1.put("安全仪表连锁回路旁路数的指标编码", "-");
            xinxi1.put("issue", "false");
            Array.add(xinxi1);
        } else if (bitNumber.equals("SCADA_DO_HV2612")) {
            xinxi2.put("id", "SCADA_DO_HV2612");
            xinxi2.put("所属区域名称", "车辆装车站");
            xinxi2.put("设备名称", "HV-2612紧急切断阀");
            xinxi2.put("指标名称", "HV2612紧急切断阀控制");
            xinxi2.put("实时●数值", String.format("%.2f", AV) + " MPa");
            xinxi2.put("单位", "");
            xinxi2.put("低低报", "-");
            xinxi2.put("低报", "-");
            xinxi2.put("高报", "-");
            xinxi2.put("高高报", "-");
            xinxi2.put("量程下限", "-");
            xinxi2.put("量程上限", "-");
            xinxi2.put("位号", "SCADA_DO_HV2612");
            xinxi2.put("重点监管工艺细类", "Z1");
            xinxi2.put("安全仪表连锁回路总数", "-");
            xinxi2.put("安全仪表系统投用状态的指标编码", "-");
            xinxi2.put("安全仪表连锁回路旁路数的指标编码", "-");
            xinxi2.put("issue", "false");
            Array.add(xinxi2);
        } else if (bitNumber.equals("SCADA_DI_HV2612")) {
            xinxi2.put("id", "SCADA_DI_HV2612");
            xinxi3.put("所属区域名称", "车辆装车站");
            xinxi3.put("设备名称", "HV-2612紧急切断阀");
            xinxi3.put("指标名称", "HV2612紧急切断阀控制");
            xinxi3.put("实时●数值", String.format("%.2f", AV) + " MPa");
            xinxi3.put("单位", "");
            xinxi3.put("低低报", "-");
            xinxi3.put("低报", "-");
            xinxi3.put("高报", "-");
            xinxi3.put("高高报", "-");
            xinxi3.put("量程下限", "-");
            xinxi3.put("量程上限", "-");
            xinxi3.put("位号", "SCADA_DI_HV2612");
            xinxi3.put("重点监管工艺细类", "Z1");
            xinxi3.put("安全仪表连锁回路总数", "-");
            xinxi3.put("安全仪表系统投用状态的指标编码", "-");
            xinxi3.put("安全仪表连锁回路旁路数的指标编码", "-");
            xinxi3.put("issue", "false");
            Array.add(xinxi3);
        }


        jsonObject.put("array", Array);
        WebSocketTest.sendInfo(jsonObject.toJSONString(), "connect");
//
//        JSONObject jsonObject2 = new JSONObject();
//        JSONObject json2 = new JSONObject();
//        jsonObject2.put("instruction","showpoi");
//        json2.put("showtype","group");
//        json2.put("poigroup","production");
//        json2.put("poitype","message");
//        jsonObject2.put("param",json2);
////        WebSocketTest.sendInfo(jsonObject2.toJSONString(), "connect");
//        for (int i = 0; i < 2; i++) {
//            if (i == 0) {
//                WebSocketTest.sendInfo(jsonObject.toJSONString(), "connect");
//            } else {
//                WebSocketTest.sendInfo(jsonObject2.toJSONString(), "connect");
//            }
//        }
    }
}
